Displaying object with combination of text and image

I have a script that is displaying any objects that have some kind of difference between 2 baselines.  Everything was working fine until I came across an object that had both text and an image.  When I get one of these objects, nothing is being displayed.  Here is my current code:

RichText rtf;
if (o2."*Object Type" "" == "Figure") {
    string s = richTextWithOle(o2."Object Text");
    for rtf in s do {
        if (rtf.isOle) {
            EmbeddedOleObject ole = rtf.getEmbeddedOle;
            string fileNameHTML = "images\\" moduleName "_Image" ++numImages ".png";
            string fileName = filePath fileNameHTML;        //filePath is the path of where HTML file is saved
            string errMsg = exportPicture(ole, fileName, formatPNG);
            if (!null errMsg) {
                htmlBuffer += "ERRORL " errMsg "\n";
            } else {
                int imgWidth, imgHeight;
                getOleWidthHeight(ole, imgWidth, imgHeight);
                if (imgWidth > 450)
                    htmlBuffer += "<img src=\"" fileNameHTML "\" width=\"75%\">\n";
                else
                    htmlBuffer += "<img src=\"" fileNameHTML "\" width=\"" imgWidth "px\">\n";
            }
        }
    }
} else {
    htmlBuffer += o2."Object Text" "";
}

When I hit an object with both text and an image, I am getting into the for-loop, but it only goes through once.  I would have expected it to loop twice: once for the text element and again for the image.  Here is what the object looks like.  The word "<Picture>" is actual text.

 

Chris

 


chrscote - Thu Jan 12 09:01:47 EST 2017

Re: Displaying object with combination of text and image
Antonio__Norkus - Thu Jan 12 09:46:27 EST 2017

I think that the picture has been added using the Insert->Picture... method (which creates a "Picture Object") rather than Insert->OLE Object...(which embeds the OLE in Object Text).

See the following function in the DXL ref manual:

string exportPicture(Object obj, string fileName, int format)

Re: Displaying object with combination of text and image
chrscote - Fri Jan 13 14:20:32 EST 2017

Antonio__Norkus - Thu Jan 12 09:46:27 EST 2017

I think that the picture has been added using the Insert->Picture... method (which creates a "Picture Object") rather than Insert->OLE Object...(which embeds the OLE in Object Text).

See the following function in the DXL ref manual:

string exportPicture(Object obj, string fileName, int format)

I have spoken with the person who input the images and was told that the same method was used throughout the document.  The newly attached image shows 2 items with images.  When I run the script above, the green square with the white 5 (#3632) appears and is exported fine.  But the item with the text "<Picture>" and the white square with the question mark (#3626) doesn't display anything.  Neither the text nor the image are displayed.  I'm not quite sure what I need to do to at least display the text.

 

 


Attachments

picture.PNG

Re: Displaying object with combination of text and image
7XUT_Antonio_Norkus - Fri Jan 13 15:43:47 EST 2017

I believe the text "<Picture>" is meta-data provided by DOORS to indicate a picture object.

As 3626 has no Object Text, it will never get to the exportPicture line in your code.

You want the following structure:

 

if (pictureObject) exportPicture

else check Object Text for OLEs

Re: Displaying object with combination of text and image
chrscote - Tue Jan 17 13:02:07 EST 2017

7XUT_Antonio_Norkus - Fri Jan 13 15:43:47 EST 2017

I believe the text "<Picture>" is meta-data provided by DOORS to indicate a picture object.

As 3626 has no Object Text, it will never get to the exportPicture line in your code.

You want the following structure:

 

if (pictureObject) exportPicture

else check Object Text for OLEs

I have fixed my script so that it now prints out the images to my html document.  I added an else-statement to the rtf.isOle statement in which I am using exportPicture on the object instead of getting the embedded OLE.  For those who are interested, here is the code I added:

else {
    htmlBuffer += o2."Object Text" "";
    string fileNameHTML = "images\\" moduleName "_Image" ++numImages ".png";
    string fileName = filePath fileNameHTML;
    string errMsg = exportPicture(o2, fileName, formatPNG);
    if (!null errMsg) {
        htmlBuffer += "ERROR: " errMsg "\n";
    } else {
        getPictWidthHeight(o2, imgWidth, imgHeight);
        if (imgWidth > 450)
            htmlBuffer += "<img src=\"" fileNameHTML"\" width=\"75%\">\n";
        else
            htmlBuffer += "<img src=\"" fileNameHTML "\" width=\"" imgWidth "px\">\n";
    }
}

However, now I have a different issue...  Some, not all, of the images are giving me a width and height of 0.  I have even tried presetting the width to a value of 449 so it would go through the else-statement, but it still gets changed to 0.  Is there a way to get this info from the exported image instead?  Just curious.

 

Chris

Re: Displaying object with combination of text and image
Mathias Mamsch - Thu Jan 19 06:18:34 EST 2017

chrscote - Tue Jan 17 13:02:07 EST 2017

I have fixed my script so that it now prints out the images to my html document.  I added an else-statement to the rtf.isOle statement in which I am using exportPicture on the object instead of getting the embedded OLE.  For those who are interested, here is the code I added:

else {
    htmlBuffer += o2."Object Text" "";
    string fileNameHTML = "images\\" moduleName "_Image" ++numImages ".png";
    string fileName = filePath fileNameHTML;
    string errMsg = exportPicture(o2, fileName, formatPNG);
    if (!null errMsg) {
        htmlBuffer += "ERROR: " errMsg "\n";
    } else {
        getPictWidthHeight(o2, imgWidth, imgHeight);
        if (imgWidth > 450)
            htmlBuffer += "<img src=\"" fileNameHTML"\" width=\"75%\">\n";
        else
            htmlBuffer += "<img src=\"" fileNameHTML "\" width=\"" imgWidth "px\">\n";
    }
}

However, now I have a different issue...  Some, not all, of the images are giving me a width and height of 0.  I have even tried presetting the width to a value of 449 so it would go through the else-statement, but it still gets changed to 0.  Is there a way to get this info from the exported image instead?  Just curious.

 

Chris

Do you have an example DMA to test? Regards, Mathias